
//946.验证栈序列
class Solution {
public:
    bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
        //模拟栈的亚压栈和出栈操作
        int n=pushed.size(),j=0;
        stack<int> st;  //用st来模拟栈
        for(int i=0;i<n;i++)
        {
            st.push(pushed[i]);
            while(!st.empty()&&st.top()==popped[j]) 
            {
                j++;
                st.pop();
            }
        }
        return st.empty();
    }
};